package hash.leetcode;

import java.util.Arrays;

/**
 * @Description: 比较字符串最小字母出现频次
 * @Author Stark
 * @Date 2022/3/21 21:16
 **/
public class Num1170_NumSmallerByFrequency {
    public static int[] numSmallerByFrequency(String[] queries, String[] words) {
        int[] qArr = new int[queries.length];
        int[] wArr = new int[words.length];
        for (int i = 0; i < queries.length; i++) {
            qArr[i] = count(queries[i]);
        }
        System.out.println(Arrays.toString(qArr));
        for (int i = 0; i < words.length; i++) {
            wArr[i] = count(words[i]);
        }
        Arrays.sort(wArr);
        System.out.println(Arrays.toString(wArr));
        int[] answers = new int[qArr.length];
        for (int i = 0; i < qArr.length; i++) {
            for (int j = 0; j < wArr.length; j++) {
                if(qArr[i] < wArr[j]){
                    answers[i] = wArr.length - j;
                    break;
                }
            }
        }
        return answers;
    }

    private static int count(String str) {
        char ch = str.charAt(0);
        for (int i = 0; i < str.length(); i++) {
            if(ch > str.charAt(i)){
                ch = str.charAt(i);
            }
        }
        int sum = 0;
        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i) == ch){
                sum++;
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        String[] q = new String[]{"bba","abaaaaaa","aaaaaa","bbabbabaab","aba","aa","baab","bbbbbb","aab","bbabbaabb"};
        String[] w = new String[]{"aaabbb","aab","babbab","babbbb","b","bbbbbbbbab","a","bbbbbbbbbb","baaabbaab","aa"};
        numSmallerByFrequency(q,w);
    }
}
